package com.douqu.game;

import com.douqu.game.configManager.ConfigCreate;
import com.douqu.game.fileManager.FileManager;
import com.douqu.game.mergeManager.MergeManager;
import com.douqu.game.serverManager.ServerManager;

import javax.swing.*;
import java.awt.*;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2018-01-29 14:12
 */
public class MainFrame extends JFrame {

    public static final int WIDTH = 650;

    public static final int HEIGHT = 900;

    //菜单 文件管理 合服管理 配置管理
    private JButton fileManager,mergeManager,configManager;//serverManger,;

    public static Font font18 = new Font("宋体", 0, 18);
    public static Font font22 = new Font("微软雅黑", 0, 22);
    private Container container;
    public MainFrame()
    {
        setLayout(null);
        setSize(WIDTH, HEIGHT);
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation((d.width-WIDTH)>>1, (d.height-HEIGHT)>>1);
        setResizable(false);

        setTitle("服务器配置文件管理工具");
        setUndecorated(false);

        setForeground(Color.BLACK);

        JMenuBar bar = new JMenuBar();
        JPanel p = new JPanel();
        p.setBounds(0,0,600,20);
        p.setLayout(null);
        setContentPane(p);
        setJMenuBar(bar);

        fileManager = new JButton("文件管理工具");
        mergeManager = new JButton("合服管理工具");

        configManager = new JButton("一键生成配置");
        fileManager.setBackground(Color.cyan);
        mergeManager.setBackground(Color.cyan);

        configManager.setBackground(Color.cyan);

        bar.add(fileManager);
        bar.add(mergeManager);

        bar.add(configManager);

        container = getContentPane();
        container.setLayout(null);
        container.setBackground(new Color(19, 71, 100));
        container.setBounds(20, 10, 600, 870);
        fileManager.addActionListener((event)-> {
            fileManager(container);
        });
        mergeManager.addActionListener((event)->{
            mergeManager(container);
        });

        configManager.addActionListener((event)->{
            configManager(container);
        });
        //设置关闭方式
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //设置可视化
        setVisible(true);

        //打开就加载
        fileManager(container);
    }

    public void configManager(Container container){
        container.removeAll();
        fileManager.setBackground(Color.cyan);
        mergeManager.setBackground(Color.cyan);
        configManager.setBackground(Color.red);
        new ConfigCreate(container,this);
    }

    /**
     * 服务器功能列表
     * @param container
     */
    public void serverManger(Container container){
        container.removeAll();
        fileManager.setBackground(Color.cyan);
        mergeManager.setBackground(Color.cyan);
        configManager.setBackground(Color.cyan);
        new ServerManager(container,this);
    }

    /**
     * 文件管理工具
     * @param container
     */
    private void fileManager(Container container){
        container.removeAll();
        fileManager.setBackground(Color.red);
        mergeManager.setBackground(Color.cyan);
        configManager.setBackground(Color.cyan);
        new FileManager(container,this);
    }

    private void mergeManager(Container container){
        container.removeAll();
        mergeManager.setBackground(Color.red);
        fileManager.setBackground(Color.cyan);
        configManager.setBackground(Color.cyan);
        //serverManger.setBackground(Color.cyan);
        new MergeManager(container,this);
    }
}

